/**
 * @description 计算学习总时长
 * 
 */

const dayjs = require("dayjs");

// const start = dayjs('2019-01-24')
// const end = dayjs('2019-01-25')
// var time = end.diff(start)
// console.log("两时间相差：", time,"\n计算秒：",time/1000,"天数是：",time/(1*24*60*60*1000)) // 20214000000 默认单位是毫秒
const computedTimeTotal = (list = []) => {
    let sum = 0;//分钟
    if (list.length > 0) {
        list.forEach(item => {
            console.log(item)
            const { createDate, startTime, endTime } = item
            // console.log("时间相关：",dayjs(createDate).format("YYYY-MM-DD"), startTime, endTime)
            // 转成标准时间先
            const start = dayjs(`${dayjs(createDate).format("YYYY-MM-DD")} ${startTime}`)
            const end = dayjs(`${dayjs(createDate).format("YYYY-MM-DD")} ${endTime}`)
            var time = end.diff(start)
            sum = Number(sum) + Number(time)
            // console.log("相差多少毫秒:"+time)
        })
    }


    return sum;
}
module.exports = {
    computedTimeTotal
}